package com.leyikao.controller;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

import com.leyikao.util.HttpRequest;
import com.leyikao.util.PropertiesUtil;
import com.leyikao.util.ToolUtil;
import com.leyikao.util.UploadUtil;


/**
 * 用户登录注册<br>
 *
 * @author LoadChange
 *
 */
@Controller
@RequestMapping("/enterprise")
public class EnterpriseCtrl {
	@SuppressWarnings("unused")
	private static final Logger logger = LoggerFactory.getLogger(EnterpriseCtrl.class);

	/**
	 * 登录
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("/login")
	public String login(HttpServletRequest request,Model model) {
		model.addAttribute("WebSite", "登录")
		 	 .addAttribute("nav_tag","")
		 	 .addAttribute("flag","0");
		return "enterprise/login";
	}
	/**
	 * 注册
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("/reg_start")
	public String reg_start(HttpServletRequest request,Model model) {
		model.addAttribute("WebSite", "注册")
		 	 .addAttribute("nav_tag","")
		 	 .addAttribute("flag","1");
		return "enterprise/register";
	}
	/**
	 * 退出登录
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("/loginOut")
	public String loginOut(HttpServletRequest request,Model model) {
		request.getSession().invalidate();
		model.addAttribute("WebSite", "登录")
		 	 .addAttribute("nav_tag","")
		 	 .addAttribute("flag","0");
		return "enterprise/login";
	}
	/**
	 * 登录校验
	 * 
	 * @param request
	 * @return
	 */
	@SuppressWarnings({ "unchecked"})
	@ResponseBody
	@RequestMapping("/verifyLogin")
	public Map<String, Object> verifyLogin(HttpServletRequest request,Model model) {
		Map<String, Object> mapJson = new HashMap<String, Object>();
		//获取用户名和密码
		//String userName = request.getSession().getAttribute("userName").toString();
		String userName = request.getParameter("userName");
		String paw = request.getParameter("password");
		String password=ToolUtil.MD5(ToolUtil.MD5(paw).toLowerCase()).toLowerCase();
		//验证码
		String kaptchaExpected = (String)request.getSession().getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);   
		String kaptchaReceived = request.getParameter("chkCode");   
		if (kaptchaReceived != null && kaptchaExpected.equalsIgnoreCase(kaptchaReceived)){ 
				HttpRequest hreq = new HttpRequest();
				String params = "\"ent_login\",\"username\":\""+userName+"\",\"password\":\""+password+"\"";
				String json = hreq.post(params);
				JSONObject jsonObject = JSONObject.fromObject(json);
				System.out.println(jsonObject);
				mapJson = JSONObject.fromObject(jsonObject);
				if(1==Integer.valueOf(mapJson.get("result").toString())){
					String enterprise = mapJson.get("data").toString();
					String enterpriseInfo = enterprise.substring(1, enterprise.length()-1);
					JSONObject enterpriseObject = JSONObject.fromObject(enterpriseInfo);
					Map<String, Object> enterpriseInfoMap = JSONObject.fromObject(enterpriseObject);
					int uid = Integer.valueOf(enterpriseInfoMap.get("uid").toString());
					//初始化企业中心
					Map<String, Object> mapInfo = initEnterpriseInfo(uid);
					request.getSession().invalidate();
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
					request.getSession().setAttribute("loginDateStr", sdf.format(new Date()));
					request.getSession().setMaxInactiveInterval(1800);
					request.getSession().setAttribute("userName", userName);//用户名
					request.getSession().setAttribute("enterpriseInfo", enterpriseInfo);//登录信息
					request.getSession().setAttribute("enterpriseInit", mapInfo.get("data"));//初始化信息
				}
			}else{
				mapJson.put("result", 0);
				mapJson.put("message", "验证码错误!");
			}
		
		model.addAttribute("WebSite", "登录")
			 .addAttribute("nav_tag","");
		return mapJson;
		
	}
	/**
	 * 获取手机验证码
	 * 
	 * @param request
	 * @return
	 */
	@ResponseBody
	@SuppressWarnings({"unchecked" })
	@RequestMapping("/verifyCode")
	public Map<String, Object> verifyCode(HttpServletRequest request,Model model) {
		//获取参数
		String phone = request.getParameter("phone");
		
		HttpRequest hreq = new HttpRequest();
		String params = "\"ent_reg_verify\",\"mob_no\":\""+phone+"\"";
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
		Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
  
		model.addAttribute("WebSite", "注册")
			 .addAttribute("nav_tag","")
			 .addAllAttributes(mapJson);
		return mapJson;
	}
	/**
	 * 忘记密码获取手机验证码
	 * 
	 * @param request
	 * @return
	 */
	@ResponseBody
	@SuppressWarnings({"unchecked" })
	@RequestMapping("/verifyForgot")
	public Map<String, Object> verifyForgot(HttpServletRequest request,Model model) {
		//获取参数
		String phone = request.getParameter("phone");
		
		HttpRequest hreq = new HttpRequest();
		String params = "\"ent_forget_verify\",\"mob_no\":\""+phone+"\"";
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
		Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
  
		model.addAttribute("WebSite", "忘记密码")
			 .addAttribute("nav_tag","")
			 .addAllAttributes(mapJson);
		return mapJson;
	}
	/**
	 * 注册
	 * 
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/register")
	@SuppressWarnings({"unchecked" })
	public Map<String, Object> register(HttpServletRequest request,Model model) {
		//获取参数
		String mob_no = request.getParameter("phone");
		String paw = request.getParameter("paw");
		String verify = request.getParameter("verify");
		String password=ToolUtil.MD5(ToolUtil.MD5(paw).toLowerCase()).toLowerCase();
		HttpRequest hreq = new HttpRequest();
		String params = "\"ent_reg_info\",\"mob_no\":\""+mob_no+"\",\"password\":\""+password+"\",\"verify\":\""+verify+"\"";
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
		Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
		 
		model.addAttribute("WebSite", "注册")
			 .addAttribute("nav_tag","")
			 .addAllAttributes(mapJson);
		return mapJson;
	}
	/**
	 * 注册服务协议
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("/serviceAgreement")
	public String serviceAgreement(HttpServletRequest request,Model model) {
		model.addAttribute("WebSite", "E朝朝用户服务协议")
			 .addAttribute("nav_tag","");
		return "enterprise/serviceAgreement";
	}
	/**
	 * 忘记密码
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("/forgot")
	public String forgotPaw(HttpServletRequest request,Model model) {
		model.addAttribute("WebSite", "修改密码")
			 .addAttribute("nav_tag","");
		return "enterprise/forgot";
	}
	/**
	 * 注册验证码验证
	 */
	@ResponseBody
	@RequestMapping("/verify")
	@SuppressWarnings({"unchecked" })
	public Map<String, Object> verify(HttpServletRequest request,Model model) {
		//获取参数
		String mob_no = request.getParameter("phone");
		String verify = request.getParameter("verify");
		HttpRequest hreq = new HttpRequest();
		String params = "\"ent_reg_check\",\"mob_no\":\""+mob_no+"\",\"verify\":\""+verify+"\"";
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
		Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
		 
		model.addAttribute("WebSite", "忘记密码")
			 .addAttribute("nav_tag","")
			 .addAllAttributes(mapJson);
		return mapJson;
	}
	/**
	 * 重新登录
	 * 
	 * @param request
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@ResponseBody
	@RequestMapping("/reLogin")
	public Map<String, Object> reLogin(HttpServletRequest request,Model model) {

		//获取用户名和密码
		String userName = request.getParameter("userName");
		String paw = request.getParameter("password");
		String verify = request.getParameter("verify");
		String password=ToolUtil.MD5(ToolUtil.MD5(paw).toLowerCase()).toLowerCase();
		HttpRequest hreq = new HttpRequest();
		String params = "\"ent_forget_newpassword\",\"mob_no\":\""+userName+"\",\"verify\":\""+verify+"\",\"new_password\":\""+password+"\"";
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
		System.out.println(jsonObject);
		Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);//修改密码
		Map<String, Object> mapLogin =new HashMap<String, Object>();
		//修改密码成功  
		if("1".equals(mapJson.get("result").toString())){
			//登录
			String params_login = "\"ent_login\",\"username\":\""+userName+"\",\"password\":\""+password+"\"";
			String json_login = hreq.post(params_login);
			JSONObject loginObject = JSONObject.fromObject(json_login);
			System.out.println(loginObject);
			mapLogin = JSONObject.fromObject(loginObject);
			String enterprise = mapLogin.get("data").toString();
			String enterpriseInfo = enterprise.substring(1, enterprise.length()-1);
			
			JSONObject enterpriseObject = JSONObject.fromObject(enterpriseInfo);
			Map<String, Object> enterpriseInfoMap = JSONObject.fromObject(enterpriseObject);
			int uid = Integer.valueOf(enterpriseInfoMap.get("uid").toString());
			//初始化企业中心
			Map<String, Object> mapInfo = initEnterpriseInfo(uid);
			request.getSession().invalidate();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
			request.getSession().setAttribute("loginDateStr", sdf.format(new Date()));
			request.getSession().setMaxInactiveInterval(1800);
			request.getSession().setAttribute("userName", userName);//用户名
			request.getSession().setAttribute("enterpriseInfo", enterpriseInfo);//登录信息
			request.getSession().setAttribute("enterpriseInit", mapInfo.get("data"));//初始化信息
		}else{
			mapLogin.put("message", mapJson.get("message"));
		}
		model.addAttribute("WebSite", "E朝朝企业中心")
			 .addAttribute("nav_tag","企业中心");
		return mapLogin;
	}
	/**
	 * 查询企业中心
	 * 
	 * @param request
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("/viewCenter")
	public String queryEnterpriseCenter(HttpServletRequest request,Model model) {
		//从session获取用户信息
		String enterpriseInfo = request.getSession().getAttribute("enterpriseInfo").toString();
		JSONObject enterpriseObject = JSONObject.fromObject(enterpriseInfo);
		Map<String, Object> enterpriseInfoMap = JSONObject.fromObject(enterpriseObject);
		//查询企业信息
		int uid = Integer.valueOf(enterpriseInfoMap.get("uid").toString());
		HttpRequest hreq = new HttpRequest();
		String params = "\"ent_my_info_view\",\"ent_user_id\":\""+uid+"\"";
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
		System.out.println(jsonObject);
		Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
		//企业联系人信息
		String params_user = "\"ent_my_contactperson_view\",\"ent_user_id\":\""+uid+"\"";
		String json_user = hreq.post(params_user);
		JSONObject userObject = JSONObject.fromObject(json_user);
		System.out.println(userObject);
		Map<String, Object> mapUser = JSONObject.fromObject(userObject);
		
		//初始化企业中心
		Map<String, Object> mapInfo = initEnterpriseInfo(uid);
		request.getSession().setAttribute("enterpriseInit", mapInfo.get("data"));//初始化信息
		
		model.addAttribute("WebSite", "E朝朝企业中心")
			 .addAttribute("nav_tag","企业中心")
			 .addAttribute("enterpriseList", mapJson.get("data"))
			 .addAttribute("userList", mapUser.get("data"))
			 .addAttribute("industry_id1", 0);
		
		String flagString = mapJson.get("data").toString();
		int flag_a = flagString.indexOf("company_name");
		int flag_b = flagString.indexOf("industry_id");
		String flag_=flagString.substring(flag_a+15,flag_b-3);
		if(flag_!=null&&!"".equals(flag_)){
			return "enterprise/viewEnterpriseInfo";
		}else{
			return "enterprise/enterpriseInfo";
		}
		
	}
	/**
	 * 编辑企业中心
	 * 
	 * @param request
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("/editCenter")
	public String editEnterpriseCenter(HttpServletRequest request,Model model) {
		//从session获取用户信息
		String enterpriseInfo = request.getSession().getAttribute("enterpriseInfo").toString();
		JSONObject enterpriseObject = JSONObject.fromObject(enterpriseInfo);
		Map<String, Object> enterpriseInfoMap = JSONObject.fromObject(enterpriseObject);
		//查询企业信息
		int uid = Integer.valueOf(enterpriseInfoMap.get("uid").toString());
		HttpRequest hreq = new HttpRequest();
		String params = "\"ent_my_info_view\",\"ent_user_id\":\""+uid+"\"";
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
		System.out.println(jsonObject);
		Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
		//企业联系人信息
		String params_user = "\"ent_my_contactperson_view\",\"ent_user_id\":\""+uid+"\"";
		String json_user = hreq.post(params_user);
		JSONObject userObject = JSONObject.fromObject(json_user);
		System.out.println(userObject);
		Map<String, Object> mapUser = JSONObject.fromObject(userObject);
		
		//查询父级所属行业"industry_id2":"33","ent_type
		String industryString = mapJson.get("data").toString();
		int industry_a = industryString.indexOf("industry_id2");
		int industry_b = industryString.indexOf("ent_type");
		int industryFlag=Integer.valueOf(industryString.substring(industry_a+15,industry_b-3));
		String parent = parentList(industryFlag,"industry");
		System.out.println(parent);
		//初始化企业中心
		Map<String, Object> mapInfo = initEnterpriseInfo(uid);
		request.getSession().setAttribute("enterpriseInit", mapInfo.get("data"));//初始化信息
		
		model.addAttribute("WebSite", "E朝朝企业中心")
			 .addAttribute("nav_tag","企业中心")
			 .addAttribute("enterpriseList", mapJson.get("data"))
			 .addAttribute("userList", mapUser.get("data"))
			 .addAttribute("industry_id1", parent);
		return "enterprise/enterpriseInfo";
	}
	/**
	 * 保存企业信息
	 * 
	 * @param request
	 * @return
	 * @throws IOException 
	 * @throws IllegalStateException 
	 */
	@SuppressWarnings({ "unchecked" })
	@RequestMapping("/saveEnterpriseInfo")
	public String saveEnterpriseCenter(HttpServletRequest request,Model model) throws IllegalStateException, IOException {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		//获取登录用户信息
		String enterpriseInfo = request.getSession().getAttribute("enterpriseInfo").toString();
		JSONObject enterpriseObject = JSONObject.fromObject(enterpriseInfo);
		Map<String, Object> enterpriseInfoMap = JSONObject.fromObject(enterpriseObject);
		//获取企业信息参数并保存
		/*
		 * 上传图片
		 */
		
		//创建一个通用的多部分解析器 
		PropertiesUtil util=new PropertiesUtil(this.getClass().getResource("/").getPath()+"/com/leyikao/config/config.properties");
		String uploadurl =util.getProperty("upload_file_url");
		String licence_url="";
		String logo_url = "";
		int i = 0;
		CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(request.getSession().getServletContext());
		//判断 request 是否有文件上传,即多部分请求 
		if(multipartResolver.isMultipart(request)){
			MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest)request;
			//取得request中的所有文件名  
			Iterator<String> iter = multiRequest.getFileNames();
			while(iter.hasNext()){
				 MultipartFile picFile = multiRequest.getFile(iter.next());
				 if(i==0){
					 if(picFile.getSize()>0){
						//取得当前上传文件的文件名称  
					 	File showfiles = UploadUtil.filerename(picFile,request);
	                	String showfilejson = UploadUtil.toUploadFile(showfiles, "file", uploadurl, null);
	                	int flag_a = showfilejson.indexOf("data\":{\"url");
	                	licence_url=showfilejson.substring(flag_a+14,showfilejson.length()-3);
					 }else{
						 licence_url = request.getParameter("licence")==""?" ":request.getParameter("licence");
					 }
				 }else{
					 if(picFile.getSize()>0){
						 File showfiles = UploadUtil.filerename(picFile,request);
				         String showfilejson = UploadUtil.toUploadFile(showfiles, "file", uploadurl, null);
					  	 int flag_a = showfilejson.indexOf("data\":{\"url");
					  	 logo_url=showfilejson.substring(flag_a+14,showfilejson.length()-3);
					 }else{
						 logo_url = request.getParameter("logo")==""?" ":request.getParameter("logo");
					 }
				 }
				 i++;
			}
		}
		int ent_user_id=Integer.valueOf(enterpriseInfoMap.get("uid").toString());
		String company_name = request.getParameter("qymc");
		int industry_id = Integer.valueOf(request.getParameter("sshy"));
		String industry_id1 =request.getParameter("suoshu");
		if(industry_id1!=null||!"".equals(industry_id1)){
			industry_id=Integer.valueOf(industry_id1);
		}
		String ent_type = request.getParameter("qyxz");
		String city_id_1 = request.getParameter("province");
		String city_id_2 = request.getParameter("city");
		String city_id_3 = request.getParameter("district");
		String address = request.getParameter("didian");
		String intro = request.getParameter("gsjj");
		String company_size = request.getParameter("rsgm");
		String web_site = request.getParameter("gswz");
		HttpRequest hreq = new HttpRequest();
		String params = "\"ent_my_info_save\",\"ent_user_id\":\""+ent_user_id+"\",\"company_name\":\""+company_name+"\",\"industry_id\":\""+industry_id+"\",\"ent_type\":\""+ent_type+"\",\"city_id_1\":\""+city_id_1+"\",\"city_id_2\":\""+city_id_2+"\",\"city_id_3\":\""+city_id_3+"\",\"address\":\""+address+"\",\"licence_url\":\""+licence_url+"\",\"intro\":\""+intro+"\",\"company_size\":\""+company_size+"\",\"logo_url\":\""+logo_url+"\",\"web_site\":\""+web_site+"\"";
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
		Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
		//获取企业信息参数并保存
		String contact_no = request.getParameter("lxdh");
		String accredit_url = request.getParameter("accredit_url")==null?" ":request.getParameter("accredit_url");
		String userParams = "\"ent_my_contactperson_save\",\"ent_user_id\":\""+ent_user_id+"\",\"contact_name\":\""+company_name+"\",\"contact_no\":\""+contact_no+"\",\"accredit_url\":\""+accredit_url+"\"";
		String userJson = hreq.post(userParams);
		JSONObject jsonUser = JSONObject.fromObject(userJson);
		Map<String, Object> mapUser = JSONObject.fromObject(jsonUser);
		
		//返回提示信息
		if("0".equals(mapJson.get("result").toString())&&"0".equals(mapUser.get("result").toString())){
			resultMap.put("result", 0);
			resultMap.put("message", "企业信息提交失败,请联系管理员!");
		}else if("0".equals(mapJson.get("result").toString())){
			resultMap.put("result", 0);
			resultMap.put("message", mapJson.get("message"));
		}else{
			resultMap.put("result", 1);
			resultMap.put("message", "提交成功!");
		}
		//重新加载企业初始化信息
		Map<String, Object> mapInfo = initEnterpriseInfo(ent_user_id);
		request.getSession().setAttribute("enterpriseInit", mapInfo.get("data"));//初始化信息
		
		model.addAttribute("WebSite", "E朝朝企业中心")
			 .addAttribute("nav_tag","企业中心")
			 .addAllAttributes(resultMap);
		if("0".equals(resultMap.get("result").toString())){
			return resultMap.get("message").toString();
		}else{
			return "redirect:/enterprise/viewCenter";
		}
	}
	/**
	 * 初始化企业中心
	 * 
	 * @param request
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public Map<String, Object> initEnterpriseInfo(int uid) {
		HttpRequest hreq = new HttpRequest();
		String paramsInfo = "\"ent_my_statistics\",\"ent_user_id\":\""+uid+"\"";
		String jsonInfo = hreq.post(paramsInfo);
		JSONObject infoObject = JSONObject.fromObject(jsonInfo);
		System.out.println(infoObject);
		Map<String, Object> mapInfo = JSONObject.fromObject(infoObject);
		return mapInfo;
	}
	/**
	 * 查询父级目录
	 * 
	 * @param request
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public String parentList(int parent_id,String class_name) {
		//int parent_id=Integer.valueOf(request.getParameter("parent_id"));
		//String class_name = request.getParameter("class_name");//city、industry、job_type、major
		HttpRequest hreq = new HttpRequest();
		String params = "\"ent_get_fid\",\"id\":\""+parent_id+"\",\"class_name\":\""+class_name+"\"";
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
		System.out.println(jsonObject);
		Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
		return mapJson.get("data").toString();
	}
	/**
	 * 所属行业
	 * 
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/industryList")
	@SuppressWarnings({"unchecked" })
	public Map<String, Object> industryList(HttpServletRequest request,Model model) {
		int parent_id=Integer.valueOf(request.getParameter("parent_id"));
		HttpRequest hreq = new HttpRequest();
		String params = "\"ent_data_industry_list\",\"parent_id\":\""+parent_id+"\"";
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
		System.out.println(jsonObject);
		Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
		model.addAllAttributes(mapJson);
		return mapJson;
	}
	/**
	 * 省市县
	 * 
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/cityList")
	@SuppressWarnings({"unchecked" })
	public Map<String, Object> cityList(HttpServletRequest request,Model model) {
		int parent_id=Integer.valueOf(request.getParameter("parent_id"));
		HttpRequest hreq = new HttpRequest();
		String params = "\"ent_data_city_list\",\"parent_id\":"+parent_id;
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
		System.out.println(jsonObject);
		Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
		model.addAllAttributes(mapJson);
		return mapJson;
	}
	/**
	 * 修改密码
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("/chPaw")
	public String chagePasswordInit(HttpServletRequest request,Model model) {
		model.addAttribute("WebSite", "E朝朝企业用户修改密码")
			 .addAttribute("nav_tag","");
		return "enterprise/chagePassword";
	}
	/**
	 * 修改密码
	 * 
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/chagePassword")
	@SuppressWarnings({"unchecked" })
	public Map<String, Object> chagePassword(HttpServletRequest request,Model model) {
		//获取登录用户信息
		String enterpriseInfo = request.getSession().getAttribute("enterpriseInfo").toString();
		JSONObject enterpriseObject = JSONObject.fromObject(enterpriseInfo);
		Map<String, Object> enterpriseInfoMap = JSONObject.fromObject(enterpriseObject);
		//参数
		int ent_user_id=Integer.valueOf(enterpriseInfoMap.get("uid").toString());
		String password1 = request.getParameter("password_old");
		String password2 = request.getParameter("password_new");
		String password3 = request.getParameter("password_new2");
		String password_old=ToolUtil.MD5(ToolUtil.MD5(password1).toLowerCase()).toLowerCase();
		String password_new=ToolUtil.MD5(ToolUtil.MD5(password2).toLowerCase()).toLowerCase();
		String password_new2=ToolUtil.MD5(ToolUtil.MD5(password3).toLowerCase()).toLowerCase();
		HttpRequest hreq = new HttpRequest();
		String params = "\"ent_my_password_edit\",\"ent_user_id\":\""+ent_user_id+"\",\"password_old\":\""+password_old+"\",\"password_new\":\""+password_new+"\",\"password_new2\":\""+password_new2+"\"";
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
		System.out.println(jsonObject);
		Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
		 
		model.addAttribute("WebSite", "E朝朝企业用户修改密码")
			 .addAttribute("nav_tag","企业中心")
			 .addAllAttributes(mapJson);
		return mapJson;
	}
	

}
